$(function(){
	$.ajax({
		type:"get",
		url:"/Home/Index/xin/cid/3",
		success : function(data){
			showData(data.data)
			
		}
	});
	function showData(data){
		var newsListInfoHtml = '';
		var str=data.foud.money.slice(0,data.foud.money.length-3);
		var re=/(?=(?!(\b))(\d{3})+$)/g;
		str=str.replace(re,",");
		$(".xinNumberNum").html(str+data.foud.money.slice(data.foud.money.length-3));//善款
		$(".xin356").html(data.foud.school);//学校
		$(".xin652").html(data.foud.earnings_number)//救助儿童
		$('.counter').countUp();//数字滚动函数
		
		for(var i in data){
			if(data[i].aid){
				newsListInfoHtml+=`<li class="clearfix newsBox">
							<div class="newsListInfoDate">
								<span>${arr(data[i].ymd)[2]}</span>
								<span>${arr(data[i].ymd)[1]}.${arr(data[i].ymd)[0]}</span>
							</div>
							<div class="newsListInfos">
								<a href="/home/index/art/aid/${data[i].aid}">
									<h3>${data[i].title}</h3>
									<p>${cutstr(data[i].content,100)}</p>
								</a>
							</div>
							<div class="newsListInfoImg">
								<img src="${data[i].pic1}" alt="" />
							</div>
						</li>`
			}
		}
		$(".newsListInfo").html(newsListInfoHtml)
	}
	function cutstr(str, len) {
		var str_length = 0;
		var str_len = 0;
		str_cut = new String();
		str_len = str.length;
		for (var i = 0; i < str_len; i++) {
			a = str.charAt(i);
			str_length++;
			if (escape(a).length > 4) {
				//中文字符的长度经编码之后大于4
				str_length++;
			}
			str_cut = str_cut.concat(a);
			if (str_length >= len) {
				str_cut = str_cut.concat("...");
				return str_cut;
			}
		}
		//如果给定字符串小于指定长度，则返回源字符串；
		if (str_length < len) {
			return str;
		}
	}
	function arr(data){
		return data.split('-')
	}
})
